package com.gz.purchase.widget;



import com.gz.purchase.R;
import com.gz.purchase.app.Define;


import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RadioGroup;
import android.widget.PopupWindow.OnDismissListener;


/**
 * 入库界面填出 入库方式 备注 窗口
 * 暂时没用这这种方式 使用了dialog 代替popWindow
 *
 *
 */
public class InStoragePopWindow implements OnDismissListener, OnClickListener, RadioGroup.OnCheckedChangeListener {
	private RadioGroup rg_in_choices;
	private EditText et_notes;
	private Button bt_in_storage;
	private Button bt_cancle;
	private PopupWindow popupWindow;
	private MyOnItemClickListener listener;
	private Context context;
	private View view ;
    private String THE_WAY_INFO = Define.RADIO_BUTTOM_CGRK;

	public InStoragePopWindow(final Context context,MyOnItemClickListener listener) {
		this.context=context;
        this.listener = listener;
		view=LayoutInflater.from(context).inflate(R.layout.popwindow_layout, null);
		rg_in_choices = (RadioGroup) view.findViewById(R.id.rg_in_choices);
		et_notes = (EditText) view.findViewById(R.id.et_notes);
		bt_in_storage = (Button) view.findViewById(R.id.bt_in_storage);
		bt_cancle = (Button) view.findViewById(R.id.bt_cancle);

		popupWindow=new PopupWindow(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		popupWindow.setAnimationStyle(R.style.popWindow_anim_style);//设置popwindow的动画效果
		popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
		popupWindow.setOnDismissListener(this);// 当popWindow消失时的监听

		bt_in_storage.setOnClickListener(this);
		bt_cancle.setOnClickListener(this);
        rg_in_choices.setOnCheckedChangeListener(this);
	}

	// 当popWindow消失时响应
	@Override
	public void onDismiss() {

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
            case R.id.bt_in_storage:
                String notes = et_notes.getText().toString();
                listener.onClickOKPop(THE_WAY_INFO,notes);
				break;
			case R.id.bt_cancle:
				dissmiss();
				break;
			default:
				break;
		}
	}

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i){
            case R.id.rb_cgrk:
                THE_WAY_INFO = Define.RADIO_BUTTOM_CGRK;
                break;
            case R.id.rb_pyrk:
                THE_WAY_INFO = Define.RADIO_BUTTOM_PYRK;
                break;
            case R.id.rb_thrk:
                THE_WAY_INFO = Define.RADIO_BUTTOM_THRK;
                break;
        }
    }


    /**
     * 消除弹窗
     */
	public void dissmiss(){
		popupWindow.dismiss();
	}

    /**
     * 弹窗显示的位置
     * @param parent 父窗体
     */
	public void showAsDropDown(View parent){
		popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
		popupWindow.setFocusable(true);//设置SelectPicPopupWindow弹出窗体可点击
		popupWindow.setOutsideTouchable(true);
		popupWindow.update();

	}

    /**
     * 设置回调监听器
     * @param listener
     */
	public void setOnItemClickListener(MyOnItemClickListener listener){
		this.listener=listener;
	}



    public interface MyOnItemClickListener{
		/** 设置点击确认按钮时监听接口 */
		void onClickOKPop(String way_info,String notes);
	}

}
